//
//  EMImageEditViewController.m
//  PictureSelector
//
//  Created by Lyy on 15/8/21.
//  Copyright (c) 2015年 Lyy. All rights reserved.
//

#import "EMImageEditViewController.h"
#import "EMImageCropView.h"

typedef void(^Complete)(UIImage *clippedImage);

@interface EMImageEditViewController ()
{
    EMImageCropView *_imageCropView;
    UIImage *_image;
}
@property (nonatomic ,copy)Complete complete;

@end

@implementation EMImageEditViewController

- (instancetype)initWithImage:(UIImage *)image
                     complete:(void (^)(UIImage *clippedImage))complete {
    if (self = [super init]) {
        self.complete = complete;
        _image = image;
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"裁剪图片";
    
    _imageCropView = [[EMImageCropView alloc] initWithFrame:self.view.bounds];
    [_imageCropView originalImage:_image cropSquareSide:300];
    
    [self.view addSubview:_imageCropView];
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(save)];
    self.view.backgroundColor = [UIColor blackColor];
    self.view.layer.masksToBounds = YES;
    
}

- (void)save {
    
    [self.navigationController popToRootViewControllerAnimated:NO];
    
    self.complete(_imageCropView.cropImage);
}

- (void)dealloc {
    NSLog(@"-------------Image Edit--------------");
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
